//
//  DownSelectBar.swift
//  Game
//
//  Created by woniu on 2025/8/28.
//

import Foundation
import UIKit

class DownSelectBar: UIView {
    public var itemPressedBlock: (()->())?
    public var titleLab:UILabel!
    public var downImgView:UIImageView!
    
    override init(frame: CGRect){
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        titleLab = UILabel()
        titleLab.font = UIFont.systemFont(ofSize: 13)
        titleLab.textColor = Colors.title
        titleLab.textAlignment = .left
        self.addSubview(titleLab)
        
        downImgView = UIImageView()
        downImgView.image = UIImage(named: "箭头_向下_gray")
        downImgView.contentMode = .scaleAspectFit
        self.addSubview(downImgView)
        
        let tap = UITapGestureRecognizer(target: self, action: #selector(onTap(_:)))
        self.addGestureRecognizer(tap)
        
        self.borderSet(Colors.title3, 0.5)
        self.circular5()
    }
    
    public func update(title:String?){
        let name = title ?? ""
        if name.isEmpty{
            titleLab.text = "请选择"
            titleLab.textColor = Colors.title3
        }else{
            titleLab.text = name
            titleLab.textColor  = .black
        }
    }
    
    @objc func onTap(_ deco:UITapGestureRecognizer){
        itemPressedBlock?()
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        titleLab.frame = CGRect(x: 10, y: 0, width: self.width-35, height: self.height)
        downImgView.frame = CGRect(x: self.width-15-10, y: 0, width: 15, height: self.height)
    }
}
